<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var person = {
        personName:"zhangsan",
        age:20,
        sayHello:function(){
            console.log("hello");
        }
    }
    //第一种写法，最常用写法，对象.属性名
    //对象.方法名
    console.log(person.age);
    person.sayHello();

    //第二种写法  对象["属性名"]
    console.log(person["personName"]);
    person["sayHello"]();

    //区别  对象[变量]中括号中可以放变量
    var attr = "age";
    console.log(person[attr]);

    //访问对象不存在的属性，打印的是undefined
    console.log(person.hobby);

    //添加属性
    //直接添加即可
    person.hobby=["swimming","football"];
    console.log(person.hobby);

    //添加一个weight
    person["weight"]=200;
    console.log(person.weight);

    //修改属性值
    //直接修改即可
    person.age=30;
    person["age"]=30;
    console.log(person.age);

    //删除属性
    delete(person.hobby);
    delete(person["age"]);
    console.log(person);

</script>
</html>